

import 'dart:convert';

import 'book_type.dart';

class YckSourceBookAnyModel{
  String bookSourceName = "";                         // 名称
  String? bookSourceGroup;                            // 分组
  String bookSourceUrl = "";                          // 地址，包括 http/https
  dynamic bookSourceType;         // 类型，0 文本，1 音频, 3 图片
  String? bookUrlPattern;                             // 详情页url正则
  int customOrder = 0;                                // 手动排序编号
  bool enabled = true;                                // 是否启用
  bool enabledExplore = true;                          // 启用发现
  String? header;                                     // 请求头
  dynamic loginUrl;                                   // 登录地址
  dynamic loginUi;                               //登录UI
  String? loginCheckJs;                               //登录检测js
  String? bookSourceComment;                          // 注释
  int lastUpdateTime=0;                               // 最后更新时间，用于排序
  int weight=0;                                       // 智能排序的权重
  String? exploreUrl;                                 // 发现url
  dynamic ruleExplore;                           // 发现规则
  String? searchUrl;                                   // 搜索url
  dynamic ruleSearch;                             // 搜索规则
  dynamic ruleBookInfo;                         // 书籍信息页规则
  dynamic ruleToc;                                   // 目录页规则
  dynamic ruleContent;                            // 正文页规则


  YckSourceBookAnyModel.fromJson(dynamic json) {
    json = checkJson(json);
    bookSourceName = json['bookSourceName'];
    bookSourceGroup = json['bookSourceGroup'];
    bookSourceUrl = json['bookSourceUrl'];
    bookSourceType = json['bookSourceType'];
    bookUrlPattern = json['bookUrlPattern'];
    customOrder = json['customOrder'];
    enabled = json['enabled'];
    enabledExplore = json['enabledExplore'];
    header = json['header'];
    loginUrl = json['loginUrl'];
    loginUi = json['loginUi'];
    loginCheckJs = json['loginCheckJs'];
    bookSourceComment = json['bookSourceComment'];
    lastUpdateTime = json['lastUpdateTime'];
    weight = json['weight'];
    exploreUrl = json['exploreUrl'];
    ruleExplore = json['ruleExplore'];
    searchUrl = json['searchUrl'];
    ruleSearch = json['ruleSearch'];
    ruleBookInfo = json['ruleBookInfo'];
    ruleToc = json['ruleToc'];
    ruleContent = json['ruleContent'];
  }

  Map<String, dynamic> toJson() {
    var map = <String, dynamic>{};
    map['bookSourceName'] = bookSourceName;
    map['bookSourceGroup'] = bookSourceGroup;
    map['bookSourceUrl'] = bookSourceUrl;
    map['bookSourceType'] = bookSourceType;
    map['bookUrlPattern'] = bookUrlPattern;
    map['customOrder'] = customOrder;
    map['enabled'] = enabled;
    map['enabledExplore'] = enabledExplore;
    map['header'] = header;
    map['loginUrl'] = loginUrl;
    map['loginUi'] = loginUi;
    map['loginCheckJs'] = loginCheckJs;
    map['bookSourceComment'] = bookSourceComment;
    map['lastUpdateTime'] = lastUpdateTime;
    map['weight'] = weight;
    map['exploreUrl'] = exploreUrl;
    map['ruleExplore'] = ruleExplore;
    map['searchUrl'] = searchUrl;
    map['ruleSearch'] = ruleSearch;
    map['ruleBookInfo'] = ruleBookInfo;
    map['ruleToc'] = ruleToc;
    map['ruleContent'] = ruleContent;
    return map;
  }



  Map<String,dynamic> checkJson(dynamic jsonString){
    if (jsonString == null) {
      jsonString =Map();
    }else if(jsonString is String){
      try{
        jsonString = json.decode(jsonString);
        if(!(jsonString is Map<String,dynamic>)){
          jsonString =Map();
        }
      }catch (e){
        jsonString =Map();
      }
    }else if(jsonString is YckSourceBookAnyModel){
      jsonString = jsonString.toJson();
    }else if(!(jsonString is Map<String,dynamic>)){
      jsonString =Map();
    }
    return jsonString;
  }
}